﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace FeedbackWebClient.Common
{
    public class BasePage : Page
    {
        protected void RegisterStartupScript(string script)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartupScript", script, true);
        }

        protected void RegisterClientSideScriptBlock(string script)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "StartupScript", script, true);
        }
        protected void RegisterClientSideScriptBlock(string script, string scriptName)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), scriptName, script, true);
        }


        protected void ShowMessage(string msg, string title)
        {
            string strScript = "setTimeout(function(){ jAlert('" + msg + "' , '" + title + "' );}, 0);";
            //string strScript = "alert('" + msg + "' , '" + title + "' );";
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "keyMessageBox", strScript, true);
        }

        protected void ShowMessage(string msg, string title, string callback)
        {
            string strScript = "setTimeout(function(){ jAlert('" + msg + "' , '" + title + "'," + callback + ");}, 0);";
            //string strScript = "alert('" + msg + "' , '" + title + "' );";
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "keyMessageBox", strScript, true);
        }


        protected string GetFileName(string fileName)
        {
            if (fileName.LastIndexOf('\\') > -1)
            {
                return fileName.Substring(fileName.LastIndexOf('\\') + 1, fileName.Length - fileName.LastIndexOf('\\') - 1);
            }
            else
            {
                return fileName;
            }
        }


        protected bool IsValidInput(string groupName)
        {
            Page.Validate(groupName);
            return Page.IsValid;
        }

        protected bool IsValidInput()
        {
            Page.Validate();
            return Page.IsValid;
        }

        protected void ShowGenericErrorMessage()
        {
            ShowMessage("An error occured while executing your request.", "Error");
        }
    }
}